home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dspgroup / asms.arc / MODEM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-13  |  3.4 KB  |  222 lines

  1. #include <stdio.h>
  2. static int sintblc[65]={
  3.         0,
  4.       804,
  5.      1607,
  6.      2410,
  7.      3211,
  8.      4011,
  9.      4807,
  10.      5601,
  11.      6392,
  12.      7179,
  13.      7961,
  14.      8739,
  15.      9511,
  16.     10278,
  17.     11038,
  18.     11792,
  19.     12539,
  20.     13278,
  21.     14009,
  22.     14732,
  23.     15446,
  24.     16150,
  25.     16845,
  26.     17530,
  27.     18204,
  28.     18867,
  29.     19519,
  30.     20159,
  31.     20787,
  32.     21402,
  33.     22004,
  34.     22594,
  35.     23169,
  36.     23731,
  37.     24278,
  38.     24811,
  39.     25329,
  40.     25831,
  41.     26318,
  42.     26789,
  43.     27244,
  44.     27683,
  45.     28105,
  46.     28510,
  47.     28897,
  48.     29268,
  49.     29621,
  50.     29955,
  51.     30272,
  52.     30571,
  53.     30851,
  54.     31113,
  55.     31356,
  56.     31580,
  57.     31785,
  58.     31970,
  59.     32137,
  60.     32284,
  61.     32412,
  62.     32520,
  63.     32609,
  64.     32678,
  65.     32727,
  66.     32757,
  67.     32767
  68. };
  69. static int sintblf[64]={
  70.         0,
  71.        12,
  72.        25,
  73.        37,
  74.        50,
  75.        62,
  76.        75,
  77.        87,
  78.       100,
  79.       113,
  80.       125,
  81.       138,
  82.       150,
  83.       163,
  84.       175,
  85.       188,
  86.       201,
  87.       213,
  88.       226,
  89.       238,
  90.       251,
  91.       263,
  92.       276,
  93.       289,
  94.       301,
  95.       314,
  96.       326,
  97.       339,
  98.       351,
  99.       364,
  100.       376,
  101.       389,
  102.       402,
  103.       414,
  104.       427,
  105.       439,
  106.       452,
  107.       464,
  108.       477,
  109.       490,
  110.       502,
  111.       515,
  112.       527,
  113.       540,
  114.       552,
  115.       565,
  116.       578,
  117.       590,
  118.       603,
  119.       615,
  120.       628,
  121.       640,
  122.       653,
  123.       665,
  124.       678,
  125.       691,
  126.       703,
  127.       716,
  128.       728,
  129.       741,
  130.       753,
  131.       766,
  132.       779,
  133.       791
  134. };
  135. static int phasein=0,phaseout=0,freqin=2048,freqout,sigcnt=0,delaypt=0;
  136. int mask,maskl,delmask;
  137. static long hilb26[13]={ -2332,6801,7121,5551,3165,-8266,11591,-1720,-5417,
  138.             17107,-8036,9810,25949};
  139. int xn[26],qn,xhn[2][32],bit;
  140. struct ctone {
  141.     int sine,cosine
  142.     } iandq;
  143. main (argc,argv)
  144. int argc;
  145. char *argv[];
  146. {
  147.     void sincos();
  148.     FILE *f1;
  149.     int i,*store,j,k,xnpt1,xnpt2;
  150.     char *malloc();
  151.     long tmp;
  152.     f1=fopen("d:tone.pcm","wb");
  153.     store=(int *)malloc(0x8000);
  154.     srand(1);
  155.     mask = (1<<14)-1;
  156.     maskl = (1<<6)-1;
  157.     bit=1;
  158.     for (j=0;j<6;j++){
  159.     printf("%d",j);
  160.         for (i=0;i<16384;i++) {
  161.             sincos(freqin,&phasein);
  162.         if (sigcnt++==24){
  163.                 if (rand()>16384) bit=-1;
  164.                 else bit=1;
  165.                 sigcnt=0;
  166.             }
  167.         xn[delaypt]=iandq.sine*bit;
  168.         tmp=0;
  169.         for (k=0;k<13;k++) {
  170.             xnpt1=k+delaypt;
  171.             xnpt2=25-k+delaypt;
  172.             if (xnpt1>25) xnpt1 -= 26;
  173.             if (xnpt2>25) xnpt2 -= 26;
  174.             tmp += hilb26[k]*(xn[xnpt1]-xn[xnpt2]);
  175.         }
  176.         delaypt -= 1;
  177.         if (delaypt <0 ) delaypt = 25;
  178.         qn = (iandq.sine*bit);
  179.         *(store+i)=(qn>>5)+0x800;
  180.         }
  181.     fwrite((char *)store,2,16384,f1);
  182.     }
  183.     fclose(f1);
  184. }
  185. void sincos(freq,phase)
  186. int freq,*phase;
  187. {
  188.     long cosx,sinx;
  189.     int wkph,mpc,mps,coph,fiph;
  190.     wkph = *phase;
  191.     mps=1;
  192.     mpc=1;
  193. a:    switch((wkph>>12)) {
  194.         case 0: break;
  195.         case 1:{
  196.             wkph  = (1<<13)-wkph;
  197.             mpc = -1;
  198.             break;
  199.         }
  200.         default: {
  201.             wkph -= (1<<13);
  202.             mps = -1;
  203.             goto a;
  204.         }
  205.     }
  206.     coph = wkph>>6;
  207.     fiph = wkph&maskl;
  208.     sinx = sintblc[coph];
  209.     cosx = sintblc[((1<<6)-coph)];
  210.     iandq.sine = ((sinx<<16) + sintblf[fiph]*cosx)>>16;
  211.     iandq.sine *= mps;
  212.     wkph = (1<<12) - wkph;
  213.     coph = wkph>>6;
  214.     fiph = wkph&maskl;
  215.     sinx = sintblc[coph];
  216.     cosx = sintblc[((1<<6)-coph)];
  217.     iandq.cosine = ((sinx<<16) + sintblf[fiph]*cosx)>>16;
  218.     iandq.cosine *= (mps*mpc);
  219.     *phase += freq;
  220.     *phase &= mask;
  221. }
  222.